package com.me.springsimple.user.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.me.springsimple.security.user.SpringsimpleUser;
import com.me.springsimple.security.util.SecurityUtils;

@Controller
public class User01Controller {
	@RequestMapping(value = "/login.html", method = RequestMethod.GET)
	public ModelAndView view(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView();
		
		SpringsimpleUser springsimpleUser = SecurityUtils.getUser();

		if(springsimpleUser == null){
			view.setViewName("login");
		}else{
			view.setViewName("main");
		}
		
		return view;

	}
	
	@RequestMapping(value="/", method=RequestMethod.GET)
	public ModelAndView loginPage() {
		return new ModelAndView("login");
	}
	
	@RequestMapping(value="/main.html", method=RequestMethod.GET)
	public ModelAndView homePage() {
		return new ModelAndView("main");
	}
	
	@RequestMapping(value="/index.html", method=RequestMethod.GET)
	public ModelAndView indexPage() {
		return new ModelAndView("main");
	}
	
	@RequestMapping(value="moderation.html", method=RequestMethod.GET)
	public ModelAndView moderatorPage() {
		return new ModelAndView("moderation");
	}
	
	@RequestMapping(value="first.html", method=RequestMethod.GET)
	public ModelAndView firstPage() {
		return new ModelAndView("first");
	}
	
	@RequestMapping(value="second.html", method=RequestMethod.GET)
	public ModelAndView secondPage() {
		return new ModelAndView("second");
	}
	
	@RequestMapping(value="admin-first.html", method=RequestMethod.GET)
	public ModelAndView firstAdminPage() {
		return new ModelAndView("admin-first");
	}
	
	@RequestMapping(value="admin-second.html", method=RequestMethod.GET)
	public ModelAndView secondAdminPage() {
		return new ModelAndView("admin-second");
	}
}
